<template>
  <el-dialog
    :title="!dataForm.id ? '评论记录' : '评论记录'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
      <el-form-item label="" prop="addTime">
        <el-timeline>
          <el-timeline-item v-for="(item, index) in dataList" :key="index" name="index" timestamp="2018/08/19" placement="top">
            <p>{{item.createTime}}</p>
            <el-card>
              <h4>{{item.realName}}</h4>
              <p>{{item.content}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  // import 'element-ui/lib/timeline'
  export default {
    data () {
      return {
        isDisabled: false,
        visible: false,
        dialogImageUrl: '',
        dialogVisible: false,
        dataList: [],
        dataForm: {
          id: 0
        },
        dataRule: {}
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.isDisabled = false
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/good/comment/getCommentReplyListById/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataList = data.data
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        if (this.dataForm.sendMoney > this.dataForm.commissionMoney) {
          this.$message.error('打款金额不能大于推广余额')
          return false
        }
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.isDisabled = true
            this.$http({
              url: this.$http.adornUrl(`/user/finance/modifyMoneyById`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'username': this.dataForm.username,
                'trueName': this.dataForm.trueName,
                'realName': this.dataForm.realName,
                'userTypes': this.dataForm.userTypes,
                'commissionMoney': this.dataForm.commissionMoney,
                'yesExtract': this.dataForm.yesExtract,
                'sendMoney': this.dataForm.sendMoney
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
